package com.syni.mdd.yhd.common.all.controller.api.business;

import com.alibaba.fastjson.JSON;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.sjb.common.component.utils.common.utils.RpcResponseVo;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.constants.ResultCode;
import com.syni.mdd.yhd.common.all.constants.ResultMsg;
import com.syni.mdd.yhd.common.all.entity.BmsBusinessInfo;
import com.syni.mdd.yhd.common.all.service.BmsBusinessinfoService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ParamsMap;
import com.syni.mdd.yhd.common.all.vo.rq.businessInfo.AddBusinessAlipayInfoVo;
import com.syni.mdd.sjb.common.component.utils.feign.service.mddAll.BusinessInfoRestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @className BusinessInfoRestApi
 * @description TOO
 * @Author cfx
 * @DATE 2020/4/6 22:14
 * @VERSION 1.0
 **/
@RestController
@RequestMapping("/apiBusinessInfo")
public class BusinessInfoRestApi implements BusinessInfoRestService{

    @Autowired
    BmsBusinessinfoService bmsBusinessinfoService;

    @GetMapping("/getBusinessInfo")
    public RpcResponseVo getBusinessInfo(@RequestParam("businessId") Integer businessId) {
        BmsBusinessInfo bmsBusinessInfo = bmsBusinessinfoService.getBusinessInfoByBusinessId(businessId);
        if(bmsBusinessInfo == null){
            return RpcResponseVo.result(ResultCode.CODE_ERROR_05,ResultMsg.CODE_ERROR_05);
        }
        return RpcResponseVo.success(bmsBusinessInfo);
    }

    @PostMapping("/checkAliPayUid")
    public RpcResponseVo checkAliPayUid(@RequestParam("alipayUser") String alipayUser,
                                        @RequestParam("alipayUid") String alipayUid) {
        if(bmsBusinessinfoService.checkAliPayUid(alipayUser,alipayUid)){
            return RpcResponseVo.success(null);
        }
        return RpcResponseVo.result(ResultCode.CODE_ERROR_100,"检验失败");
    }

    @PostMapping("/addBusinessAlipayInfo")
    public RpcResponseVo addBusinessAlipayInfo(@RequestParam("addAlipayInfoVo") String addAlipayInfoVo) {
        AddBusinessAlipayInfoVo addBusinessAlipayInfoVo = JSON.parseObject(addAlipayInfoVo,AddBusinessAlipayInfoVo.class);
        boolean result = bmsBusinessinfoService.improveCollectionInfo(addBusinessAlipayInfoVo);
        if(result){
            return RpcResponseVo.success(ResultCode.CODE_NORMAL,ResultMsg.HAND_SUCCESS);
        }
        return RpcResponseVo.result(ResultCode.CODE_ERROR_100, ResultMsg.MSG_IDENT_UID_NO_MATCH);
    }

    @PostMapping("/confirmUidNews")
    public RpcResponseVo confirmUidNews(@RequestBody ParamsMap paramsMap) {
        Map<String,Object> retMap = bmsBusinessinfoService.payTreasureConfirm(paramsMap);
        if(ResultMapHelper.isSuccess(retMap)){
            return RpcResponseVo.success(ResultCode.CODE_NORMAL,ResultMsg.HAND_SUCCESS);
        }
        return RpcResponseVo.result(retMap.get("status").toString(), retMap.get("msg").toString());
    }
}
